package com.ruoyi.project.dataanalysis.util;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONException;
import com.alibaba.fastjson.JSONObject;
import com.ruoyi.project.dataanalysis.entity.Params;
import com.ruoyi.project.dataanalysis.entity.Problems;
import org.jsoup.Connection;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import java.io.IOException;
import java.util.*;

/**
 * @author 范莹莹
 * @version 1.0
 */
public class getProblemsData {

    public static List<Problems> getHttp(Params params)
    {
        String s_time=params.getStartTime();
        String e_time=params.getEndTime();
        String url="http://10.238.1.247/cs/pcc/core/sheet/sheetmainhistory/querylist?sheetCode=&businessNo=&acceptTimeBegin="+s_time+"+00%3A00%3A00&acceptTimeEnd="+e_time+"+23%3A59%3A59&isOver=&contactNo=&manageRange=&content=&acceptUser=&sendUser=&dealUser=Kf45159015&answerUser=&sheetTypeRoot=45165e9a2d3e487fb5b42fc59a876b9d&codeSheetTypeId=&codeBusinessType=&submitWay=&codeAcceptChannel=&noArea=&acceptCenter=&complainArea=&tenantId=UNICOM&proId=97&page=1&rows=1000&sort=acceptTime&direction=desc&_=1569201801032";
        Connection con = Jsoup.connect(url);
        String head="Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySW5mbyI6eyJ0ZW5hbnRJZCI6IlVOSUNPTSIsInByb0lkIjoiOTciLCJyY0lkIjoiIiwidXNlckNvZGUiOiJLRjQ1MTU5MDEzIiwidXNlcklkIjoiS0Y0NTE1OTAxMyIsInVzZXJOYW1lIjoi6K6h6LWr5Y2XIiwib3JnSWQiOiI5NzAxMDAyMSIsImNyZWF0ZVRpbWUiOiJUaHUgTm92IDIyIDA0OjU5OjI1IEdNVCswODowMCAyMDE4Iiwic2tpbklkIjpudWxsLCJyZW1hcmsiOiLmlrDlrqLmnI0s5paw5L2_5ZG9In0sImF1ZCI6WyJuZXdDdXN0b21lclNlcnZpY2UiXSwidXNlcl9uYW1lIjoiS0Y0NTE1OTAxMyIsImxvZ2luS2V5IjoiNzZiOTk5YjAtZmY4Yy0xMWU5LWIxNGUtM2YxNDE0YTk2OTFhIiwic2NvcGUiOlsiYWxsIl0sInBsYXRmb3JtVHlwZSI6InRlbmFudF9maWVsZCIsImV4cCI6MTU3MzAxNzgzNiwiYXV0aFR5cGUiOiJnZW5lcmFsX3Bhc3N3b3JkIiwiYXV0aG9yaXRpZXMiOlsiUk9MRTk3MDAyMSJdLCJjbGllbnRfaWQiOiJicm93c2VyIn0.9lp-iS2DoMBPYXtxdy57pfJwMSL4hX3Kxx_94t33AoA";
        //请求头设置，特别是cookie设置
        con.header("Accept", "application/json, text/javascript, */*; q=0.01");
        con.header("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
        con.header("User-Agent", "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36");
        con.header("Authorization", head);
        List<Problems> problemsList=new ArrayList<>();
        try {
            Document doc=con.ignoreContentType(true).get();
            String body = con.ignoreContentType(true).execute().body();
            System.out.println(body);
            JSONObject json = JSONObject.parseObject(body);
            JSONArray arr = json.getJSONObject("RSP").getJSONObject("DATA").getJSONArray("rows");
            System.out.println(arr);
            for(int i=0;i<arr.size();i++)
            {
                JSONObject job = arr.getJSONObject(i);
                Problems problems=new Problems();
                problems.setManagerGrid("萨尔图综合网格");
                problems.setSheet_id(job.get("sheet_id").toString());
                problems.setSheet_code(job.get("sheet_code").toString());
                problems.setBusiness_no(job.get("business_no").toString());
                problems.setCode_sheet_type_id(job.get("sheet_type_root").toString());
                problems.setSubmit_way(getSubmit_way(job.get("submit_way").toString()));
                problems.setCode_sheet_type_id(job.get("code_sheet_type_id").toString());
                problems.setServ_content(job.get("serv_content").toString());
                problems.setCode_business_type(getCode_business_type(job.get("code_business_type").toString()));
                problems.setSheet_status(getStatus_code(job.get("sheet_status").toString()));
                problemsList.add(problems);

            }


        }
        catch (IOException exception)
        {
            System.out.println(exception.getMessage());
        }
        catch (JSONException exception1)
        {
            System.out.println(exception1.getMessage());
        }
        return problemsList;
    }
   public static String getStatus_code(String gdzt)
   {
       String gdzt_zh="";
       switch (gdzt)
       {
           case "2":
               gdzt_zh="待处理";
               return gdzt_zh;
           case "4":
               gdzt_zh="待回访";
               return gdzt_zh;
           case "7":
               gdzt_zh="结束";
               return gdzt_zh;
           case "8":
               gdzt_zh="8";
               return gdzt_zh;
           case "3":
               gdzt_zh="待审核";
               return gdzt_zh;
       }

       return "";
   }
    public static String getCode_business_type(String ywlx)
    {   String ywlx_zh="";
        switch (ywlx)
        {
            case "01":
                ywlx_zh="固话";
                return ywlx_zh;
            case "02":
                ywlx_zh="宽带";
                return ywlx_zh;
            case "03":
                ywlx_zh="2G";
                return ywlx_zh;
            case "04":
                ywlx_zh="3G";
                return ywlx_zh;
            case "05":
                ywlx_zh="4G";
                return ywlx_zh;
            case "06":
                ywlx_zh="融合";
                return ywlx_zh;
            case "07":
                ywlx_zh="小灵通";
                return ywlx_zh;
            case "08":
                ywlx_zh="其他";
                return ywlx_zh;

        }
       return "";
    }
    public static String getSubmit_way(String qd)
    {
         String qd_zh="";
         switch (qd) {
             case "01":
                 qd_zh ="10010";
                 return qd_zh;
             case "02":
                 qd_zh ="10010";
                 return qd_zh;
             case "03":
                 qd_zh ="10010";
                 return qd_zh;
             case "04":
                 qd_zh ="10010";
                 return qd_zh;
             case "05":
                 qd_zh ="10010";
                 return qd_zh;
             case "06":
                 qd_zh ="10010";
                 return qd_zh;
             case "07":
                 qd_zh ="10010";
                 return qd_zh;
             case "08":
                 qd_zh ="10010";
                 return qd_zh;
             case "09":
                 qd_zh ="10010";
                 return qd_zh;
             case "10":
                 qd_zh ="10010";
                 return qd_zh;
             case "11":
                 qd_zh ="10010";
                 return qd_zh;
             case "12":
                 qd_zh ="10015升级投诉";
                 return qd_zh;
             case "13":
                 qd_zh ="10010";
                 return qd_zh;
             case "14":
                 qd_zh ="10015升级投诉";
                 return qd_zh;
             case "15":
                 qd_zh ="工信";
                 return qd_zh;
             case "16":
                 qd_zh ="工信";
                 return qd_zh;
             case "17":
                 qd_zh ="工信";
                 return qd_zh;
             case "18":
                 qd_zh ="工信";
                 return qd_zh;
             case "19":
                 qd_zh ="管局";
                 return qd_zh;
             case "20":
                 qd_zh ="管局";
                 return qd_zh;
             case "21":
                 qd_zh ="管局";
                 return qd_zh;
             case "22":
                 qd_zh ="10010";
                 return qd_zh;
             case "23":
                 qd_zh ="10010";
                 return qd_zh;
             case "24":
                 qd_zh ="10010";
                 return qd_zh;
             case "25":
                 qd_zh ="10010";
                 return qd_zh;
             case "26":
                 qd_zh ="10010";
                 return qd_zh;
             case "27":
                 qd_zh ="10010";
                 return qd_zh;
             case "28":
                 qd_zh ="10010";
                 return qd_zh;
             case "29":
                 qd_zh ="10010";
                 return qd_zh;
             case "30":
                 qd_zh ="10010";
                 return qd_zh;
             case "31":
                 qd_zh ="10010";
                 return qd_zh;
             case "32":
                 qd_zh ="10015升级投诉";
                 return qd_zh;
             case "33":
                 qd_zh ="10010";
                 return qd_zh;
             case "34":
                 qd_zh ="10015升级投诉";
                 return qd_zh;
             case "35":
                 qd_zh ="工信";
                 return qd_zh;
             case "36":
                 qd_zh ="工信";
                 return qd_zh;
             case "37":
                 qd_zh ="工信";
                 return qd_zh;
             case "38":
                 qd_zh ="工信";
                 return qd_zh;
             case "39":
                 qd_zh ="管局";
                 return qd_zh;
             case "40":
                 qd_zh ="10010";
                 return qd_zh;
             case "41":
                 qd_zh ="10010";
                 return qd_zh;
         }
        return "";
    }
}
